var t = require("../../../@babel/runtime/helpers/defineProperty"), o = getApp();

Page({
    data: {
        searchValue: "",
        goodsList: [],
        temArr: [],
        value: 1,
        selectGoods: [],
        showPrice: !1,
        page: 1,
        isLoadMore: !0,
        total_page: 0
    },
    onLoad: function(t) {
        this.getGood();
    },
    gotoUrl: function(t) {
        var o = t.currentTarget.dataset.info;
        console.log(o), wx.navigateTo({
            url: "/packageI/newRetailInventoryDetails/newRetailInventoryDetails?gid=" + o.goods_id + "&optionId=" + o.goods_option
        });
    },
    getGood: function() {
        var t = this, e = o.getNetAddresss("plugin.new-retail.frontend.index.getStock");
        o._postNetWork({
            url: e,
            data: {
                goods_name: this.data.searchValue
            },
            success: function(o) {
                var e = o.data;
                if (1 == e.result) {
                    var a = e.data.data;
                    a.forEach(function(t) {
                        t.goods_num = 1, t.goods_price = null;
                    }), t.setData({
                        goodsList: a,
                        isLoadMore: !0,
                        total_page: e.data.last_page
                    });
                } else wx.showToast({
                    title: e.msg,
                    duration: 1e3,
                    icon: "none"
                });
            },
            fail: function(t) {
                wx.hideLoading(), console.log(t.msg);
            }
        });
    },
    _getMoreData: function() {
        var t = this;
        if (this.data.isLoadMore = !1, !(this.data.page >= this.data.total_page)) {
            this.data.page += 1;
            var e = o.getNetAddresss("plugin.new-retail.frontend.index.getStock");
            o._postNetWork({
                url: e,
                data: {
                    page: this.data.page,
                    goods_name: this.data.searchValue
                },
                success: function(o) {
                    var e = o.data;
                    if (t.data.isLoadMore = !0, 1 === e.result) {
                        var a = e.data.data;
                        a.forEach(function(t) {
                            t.goods_num = 1, t.goods_price = null;
                        });
                        var s = t.data.goodsList.concat(a);
                        t.setData({
                            goodsList: s
                        });
                    } else t.data.page = t.data.page - 1, t.data.isLoadMore = !1;
                }
            });
        }
    },
    onChangeStepper: function(o) {
        var e = o.currentTarget.dataset.i;
        this.setData(t({}, "goodsList[" + e + "].goods_num", o.detail));
    },
    onSearchChange: function(t) {
        this.setData({
            searchValue: t.detail
        });
    },
    selectGoodsCheckbox: function(t) {
        this.setData({
            selectGoods: t.detail
        });
    },
    agentSalePopup: function() {
        var t = this;
        if (this.data.selectGoods.length < 1) wx.showToast({
            icon: "none",
            title: "请选择商品",
            duration: 1500
        }); else {
            var o = [];
            this.data.goodsList.forEach(function(e, a) {
                var s = a + "";
                t.data.selectGoods.indexOf(s) > -1 && o.push(e);
            }), this.setData({
                showPrice: !0,
                temArr: o
            }), console.log(this.data.temArr);
        }
    },
    blurPrice: function(o) {
        var e = o.currentTarget.dataset.i;
        this.setData(t({}, "temArr[" + e + "].goods_price", o.detail.value));
    },
    delSelectGood: function(t) {
        var o = t.currentTarget.dataset.i;
        this.data.selectGoods.splice(o, 1), this.data.temArr.splice(o, 1), this.setData({
            selectGoods: this.data.selectGoods,
            temArr: this.data.temArr
        }), this.data.selectGoods.length < 1 && (wx.showToast({
            icon: "none",
            title: "请选择商品",
            duration: 1500
        }), this.setData({
            showPrice: !1
        }));
    },
    onClose: function() {
        this.setData({
            showPrice: !1
        });
    },
    confirmAgentSale: function() {
        if (this.data.selectGoods.length < 1) wx.showToast({
            icon: "none",
            title: "请选择商品",
            duration: 1500
        }); else {
            for (var t = 0; t < this.data.temArr.length; t++) if (!this.data.temArr[t].goods_price || "" == this.data.temArr[t].goods_price) return void wx.showToast({
                icon: "none",
                title: "有商品没有填写单价！",
                duration: 2e3
            });
            var e = o.getNetAddresss("plugin.new-retail.frontend.index.onlineRetail");
            o._postNetWork({
                url: e,
                data: {
                    goods: this.data.temArr
                },
                success: function(t) {
                    var o = t.data;
                    1 == o.result ? wx.navigateTo({
                        url: "/packageH/newRetail/newRetailRetailLink/newRetailRetailLink?id=" + o.data.id
                    }) : wx.showToast({
                        title: o.msg,
                        duration: 1e3,
                        icon: "none"
                    });
                },
                fail: function(t) {
                    wx.hideLoading(), console.log(t.msg);
                }
            });
        }
    },
    freeSend: function() {
        var t = this;
        if (this.data.selectGoods.length < 1) wx.showToast({
            icon: "none",
            title: "请选择商品",
            duration: 1500
        }); else {
            var o = [], e = [];
            this.data.goodsList.forEach(function(o, a) {
                var s = a + "";
                t.data.selectGoods.indexOf(s) > -1 && e.push(o);
            }), e.forEach(function(t) {
                o.push({
                    goods_id: t.goods_id,
                    goods_option: t.goods_option,
                    goods_num: t.goods_num
                });
            });
            console.log("xpc", JSON.stringify(o)), wx.navigateTo({
                url: "/packageD/buy/myOrder_v2/myOrder_v2?tag=newRetail&goodsId=0&optionsId=0&total=0&retailState=2&goods=" + JSON.stringify(o)
            });
        }
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});